#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#define path "/tmp/test_fifo"
#define Length 1024*1024*100
int main ()
{
  int res;
  int open_fifo;
  char buffer[PIPE_BUF];
  long bytes;
  
  strcpy(buffer,"01234567890");
  if (access(path,0)== -1)
  {
    res = mkfifo(path,0777);
    if (res!=0)
    {
      printf("create fifo file error \n\n");
      return -1;
    }
  }
  printf("Process %d open FIFO O_WRONLY \n",getpid());
  open_fifo = open(path,O_WRONLY);
  if (open_fifo != -1)
  {
    while(bytes < Length)
    {
      res = write(open_fifo,buffer,PIPE_BUF);
      if (res == -1)
      {
        printf("write error on pipe \n");
        return -1;
      }
      bytes+=res;
      
    }
    close(open_fifo);
  }
  else
    return -1;
  printf("Process %d finish \n",getpid());
  return 0;
}

